< previous page page_420 next page >

Page 420
ODBCEnvironment essentially encapsulates behavior and information related to the ODBC environment. An environment handle must be allocated before you can do anything with the ODBC API. Its property is EnvHandle As Long. Its methods are allocateEnvironment() and deallocateEnvironment(), which set EnvHandle. After declaring the SQLAllocEnv in the ODBC DLL, the allocateEnvironment method will contain the following code:
Dim iReturnCode as integer
iReturnCode = SQLAllocEnv(mvarEnvHandle)
You could invoke this method in the Class_Initialize event because the returned environment handle supports multiple connections to data sources. If SQLAllocEnv returns SQL_SUCCEED, the ODBC driver manager is initialized. Memory is allocated to store information about the environment. If this function call fails, the ODBC DLLs didn't correctly initialize.
ODBCConnection encapsulates the behavior and information related to the connection. Properties include DbcHandle As Long and Status As Byte. Its methods are openConnection() and closeConnection().
ODBCResultset encapsulates behavior and information related to the sets of records with which your application works. Properties include StmtHandle As Long, SQL As String, Status As Byte, and RecordCount As Long.
Establishing a Connection Establishing a connection is essential before proceeding with further ODBC calls. The ODBCConnection class has a property, ConnHandle As Long, to hold the hDbc value of the current connection.
The openConnection method of the ODBCConnection class has the following contents:
Public Sub openConnection(argConnStr As String)
Dim lHdbc As Long, lHenv As Long, vRetCode
vRetCode = SQLAllocConnect(ByVal lHenv, lHdbc)
theODBCEnvironment.EnvHandle = lHenv
ConnHandle = lHdbc
vRetCode receives the return code value of the call. If vRetCode = SQL_SUCCEED, the connection handle is allocated some space in memory. If unsuccessful, a call to the SQLError function gives you the reason for the failure. theODBCEnvironment is an instance of the class ODBCEnvironment.

 
< previous page page_420 next page >

If you like this book, buy it!